package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.domain.SysDistrict;
import com.wuliu.system.service.ISysDistrictService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 平台全国省市区县地址库Controller
 * 
 * @author realue
 * @date 2023-10-24
 */
@Api(tags = {"行政区域控制器"})
@RestController
@RequestMapping("/system/district")
public class SysDistrictController extends BaseController {
    @Resource
    private ISysDistrictService sysDistrictService;

    /**
     * 查询平台全国省市区县地址库列表
     */
    @ApiOperation(value = "查询")
    @PreAuthorize("@ss.hasPermi('system:district:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDistrict sysDistrict) {
        startPage();
        List<SysDistrict> list = sysDistrictService.selectSysDistrictList(sysDistrict);
        return getDataTable(list);
    }

    /**
     * 导出平台全国省市区县地址库列表
     */
    @ApiOperation(value = "导出")
    @PreAuthorize("@ss.hasPermi('system:district:export')")
    @Log(title = "平台全国省市区县地址库", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysDistrict sysDistrict) {
        List<SysDistrict> list = sysDistrictService.selectSysDistrictList(sysDistrict);
        ExcelUtil<SysDistrict> util = new ExcelUtil<SysDistrict>(SysDistrict.class);
        util.exportExcel(response, list, "平台全国省市区县地址库数据");
    }

    /**
     * 获取平台全国省市区县地址库详细信息
     */
    @ApiOperation(value = "详细")
    @PreAuthorize("@ss.hasPermi('system:district:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(sysDistrictService.selectSysDistrictById(id));
    }

    /**
     * 新增平台全国省市区县地址库
     */
    @ApiOperation(value = "新增")
    @PreAuthorize("@ss.hasPermi('system:district:add')")
    @Log(title = "平台全国省市区县地址库", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysDistrict sysDistrict) {
        return toAjax(sysDistrictService.insertSysDistrict(sysDistrict));
    }

    /**
     * 修改平台全国省市区县地址库
     */
    @ApiOperation(value = "编辑")
    @PreAuthorize("@ss.hasPermi('system:district:edit')")
    @Log(title = "平台全国省市区县地址库", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysDistrict sysDistrict) {
        return toAjax(sysDistrictService.updateSysDistrict(sysDistrict));
    }

    /**
     * 删除平台全国省市区县地址库
     */
    @ApiOperation(value = "删除")
    @PreAuthorize("@ss.hasPermi('system:district:remove')")
    @Log(title = "平台全国省市区县地址库", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(sysDistrictService.deleteSysDistrictByIds(ids));
    }
}
